package notification.net;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
  
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;

public class SimpleClient {
  
   public static void main(String[] args) throws Exception {
    final String host = "localhost";  
    final int port = 8080;
          // Configure the client.
    ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(
          new NioDatagramChannelFactory(Executors.newCachedThreadPool()));
          // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
          public ChannelPipeline getPipeline() throws Exception {
             return Channels.pipeline();
              }
          });
          // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
          // Wait until the connection is closed or the connection attempt fails.
	 ChannelBuffer firstMessage = ChannelBuffers.dynamicBuffer();
	 firstMessage.writeBytes(new byte[]{0x74,0x00,0x00,0x00,0x33,0x35,0x33,0x39,0x37,0x36,0x30,0x31,0x33,
 0x34,0x34,0x35,0x34,0x38,0x35,0x00,0x4B,0x0B,(byte) 0xFB,0x70,0x00,0x00,0x00,0x03,
 0x0B,(byte) 0xBB,0x00,0x00,0x00,0x12,0x00,0x04,0x70,0x77,0x72,0x5F,
 0x65,0x78,0x74,0x00,0x2B,(byte) 0x87,0x16,(byte) 0xD9,(byte) 0xCE,(byte) 0x97,0x3B,0x40,0x0B,(byte) 0xBB,0x00,0x00,0x00,
 0x11,0x01,0x03,0x61,0x76,0x6C,0x5F,0x69,0x6E,0x70,0x75,0x74,0x73,0x00,0x00,0x00,0x00,0x01,0x0B,(byte) 0xBB,0x00,0x00,0x00,0x27,0x01,
 0x02,0x70,0x6F,0x73,0x69,0x6E,0x66,0x6F,0x00,(byte) 0xA0,0x27,(byte) 0xAF,(byte) 0xDF,0x5D,(byte) 0x98,0x48,0x40,
 0x3A,(byte) 0xC7,0x25,0x33,(byte) 0x83,(byte) 0xDD,
 0x4B,0x40,0x00,0x00,0x00,0x00,0x00,(byte) 0x80,0x5A,0x40,0x00,0x36,0x01,0x46,0x0B});
     for (int i=0; i<5; ++i)future.getChannel().write(firstMessage);
     future.getChannel().getCloseFuture().awaitUninterruptibly();
          // Shut down thread pools to exit.
     bootstrap.releaseExternalResources();
     System.out.println("Stop!");
   }
}